package com.xiaouyudeguang.common.around;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

import static com.xiaouyudeguang.common.config.MybatisPlusConfig.TABLE_NAME;

@Slf4j
@Aspect
@Component
@AllArgsConstructor
public class MybatisAround {

    private final HttpServletRequest request;

    @Pointcut("execution(* com.*.*.*.resource..*.*(..)) ||"
            + "@annotation(org.springframework.web.bind.annotation.RequestMapping) ||"
            + "@annotation(org.springframework.web.bind.annotation.PostMapping) ||"
            + "@annotation(org.springframework.web.bind.annotation.PutMapping) ||"
            + "@annotation(org.springframework.web.bind.annotation.DeleteMapping) ||"
            + "@annotation(org.springframework.web.bind.annotation.GetMapping)")
    public void mybatis() {
    }

    @Around("mybatis()")
    public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
        Object res = pjp.proceed();
        TABLE_NAME.remove();
        return res;
    }
}
